package com.cardbaobao.cardbabyclient.model;

import com.cardbaobao.cardbabyclient.base.Constant;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
 * Created by Jiangzx on 2017/9/25 17:11.
 */

public class TransactionRecordData {
    public static final int TYPE_DEBIT_RECORD=1;//收款记录
    public static final int TYPE_WITHDRAW_RECORD=2;//提现记录
    private List<Bean> dataList;

    public List<Bean> getDataList() {
        return dataList;
    }

    public void setDataList(List<Bean> dataList) {
        this.dataList = dataList;
    }

    public static class Bean{

        /**
         * fee : 2
         * rate_channel_type : KQB010101
         * state : 2
         * picture_path : /uploadFiles/uploadImgs/banner/20170919/9bf3db131c9d445199a209cd9bcba3f7.png
         * create_time : 2017-09-20 09:43:36
         * receive_amount : 9.45
         * payable_amount : 10
         * id : cbb20170926171441150641728165113
         * modify_time : 2017-09-29 15:52:34
         */

        private String fee;
        private String rate_channel_type;
        private String state;
        private String picture_path;
        private String create_time;
        private String modify_time;
        private String receive_amount;
        private String payable_amount;
        private String id;

        public String getFee() {
            return fee;
        }

        public void setFee(String fee) {
            this.fee = fee;
        }

        public String getRate_channel_type() {
            return rate_channel_type;
        }

        public void setRate_channel_type(String rate_channel_type) {
            this.rate_channel_type = rate_channel_type;
        }

        public String getState() {
            return state;
        }

        public void setState(String state) {
            this.state = state;
        }

        public String getPicture_path() {
            return picture_path;
        }

        public void setPicture_path(String picture_path) {
            this.picture_path = picture_path;
        }

        public String getCreate_time() {
            return create_time;
        }

        public void setCreate_time(String create_time) {
            this.create_time = create_time;
        }

        public String getReceive_amount() {
            return receive_amount;
        }

        public String getModify_time() {
            return modify_time;
        }

        public void setModify_time(String modify_time) {
            this.modify_time = modify_time;
        }

        public void setReceive_amount(String receive_amount) {
            this.receive_amount = receive_amount;
        }

        public String getPayable_amount() {
            return payable_amount;
        }

        public void setPayable_amount(String payable_amount) {
            this.payable_amount = payable_amount;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }
    }

    public static class ShowerBean{
        private String orderNumber;
        private String logo;
        private String channel;
        private String amount;
        private String time;
        private String status;

        public String getOrderNumber() {
            return orderNumber;
        }

        public void setOrderNumber(String orderNumber) {
            this.orderNumber = orderNumber;
        }

        public String getLogo() {
            return logo;
        }

        public void setLogo(String logo) {
            this.logo = logo;
        }

        public String getChannel() {
            return channel;
        }

        public void setChannel(String channel) {
            this.channel = channel;
        }

        public String getAmount() {
            return amount;
        }

        public void setAmount(String amount) {
            this.amount = amount;
        }

        public String getTime() {
            return time;
        }

        public void setTime(String time) {
            this.time = time;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }
    }

    public static List<ShowerBean> convertShower(List<TransactionRecordData.Bean> source,int type){
        List<ShowerBean> data=new ArrayList<>();
        if(source!=null&&source.size()>0){
            TransactionRecordData.Bean tb;
            for(int i=0,size=source.size();i<size;i++){
                tb=source.get(i);
                ShowerBean bean=new ShowerBean();
                bean.setOrderNumber(tb.getId());
                bean.setLogo(tb.getPicture_path());
                if(type==TYPE_DEBIT_RECORD){
                    //收款
                    bean.setAmount(String.format(Locale.CHINESE,
                            Constant.AMOUNT_FORMAT,
                            Double.parseDouble(tb.getPayable_amount())));
                    bean.setTime(tb.getCreate_time());
                }else{
                    //提现
                    bean.setAmount(String.format(Locale.CHINESE,
                            Constant.AMOUNT_FORMAT,
                            Double.parseDouble(tb.getReceive_amount())));
                    bean.setTime(tb.getModify_time());
                }

                String channel="";
                switch (tb.getRate_channel_type()){
                    case Constant.KQB010101:
                        channel="快捷支付";
                        break;
                    case Constant.KQB010102:
                        //微信
                        channel="微信";
                        break;
                    case Constant.KQB010103:
                        //支付宝
                        channel="支付宝";
                        break;
                    case Constant.KQB010104:
                        //京东
                        channel="京东支付";
                        break;
                    case Constant.KQB010105:
                        //QQ
                        channel="QQ支付";
                        break;
                }
                bean.setChannel(channel);
                bean.setStatus(convertStatus(tb.getState(),type));
                data.add(bean);
            }
        }
        return data;
    }

    private static String convertStatus(String status,int type){
        String statusStr="";
        switch (status){
            case "1":
                if(type==TYPE_DEBIT_RECORD){
                    statusStr="付款成功";
                }else{
                    statusStr="提现成功";
                }
                break;
            case "2":
                if(type==TYPE_DEBIT_RECORD){
                    statusStr="付款失败";
                }else{
                    statusStr="提现失败";
                }
                break;
            case "3":
                statusStr="交易处理中";
                break;
        }
        return statusStr;
    }
}
